<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>影院管理</el-breadcrumb-item>
      <el-breadcrumb-item>影院列表</el-breadcrumb-item>
      <el-breadcrumb-item>放映厅列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 分割线 -->
    <el-divider></el-divider>
    <!-- 操作按钮 -->
    <el-button type="primary" plain @click="showAddCinemaRoomlog()"
      >新增放映厅</el-button
    >
    <!-- 分割线 -->
    <el-divider></el-divider>

    <el-empty
      v-if="!tableData || tableData.length == 0"
      description="当前影院无放映厅"></el-empty>
    <div v-else>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column align="center" prop="room_name" label="放映厅名称">
        </el-table-column>
        <el-table-column
          align="center"
          prop="room_type"
          label="放映厅类型"
          width="200">
        </el-table-column>
        <el-table-column align="center" prop="room_size" label="放映厅座位数">
          <template slot-scope="scope">
            <span style="color: #666"></span>
            {{ scope.row.room_size ? scope.row.room_size : "请配置座位模板" }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button
              @click="
                $router.push(`/home/showinggon-plan/list/${scope.row.id}`)
              "
              icon="el-icon-video-camera-solid
"
              type="primary"
              title="查看排片"
              circle>
            </el-button>
            <el-button
              @click="$router.push(`/home/showinggon-plan/${scope.row.id}`)"
              type="success"
              icon="el-icon-plus
"
              title="为放映厅排片"
              circle>
            </el-button>
            <el-button
              @click="
                $router.push(`/home/cinema-room-seat-template/${scope.row.id}`)
              "
              type="warning"
              icon="el-icon-s-grid"
              title="配置放映厅座位"
              circle></el-button>
            <el-button
              @click="showDelDialog(scope.row.id)"
              type="danger"
              title="删除放映厅"
              icon="el-icon-delete"
              circle></el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 添加放映厅的对话框 -->
    <el-dialog title="添加放映厅" :visible.sync="dialogAddCienmaRoomVisible">
      <el-form :model="form">
        <el-form-item label="放映厅名称" label-width="200">
          <el-input
            style="width: 350px"
            v-model="form.room_name"
            autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="放映厅类型" label-width="200">
          <el-select
            style="width: 300px"
            v-model="form.room_type"
            placeholder="请选择放映厅类型">
            <el-option
              v-for="item in cinemaRootmTypes"
              :label="item.type_name"
              :key="item.id"
              :value="item.type_name"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAddCienmaRoomVisible = false">取 消</el-button>
        <el-button type="primary" @click="onSubmit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 添加放映厅窗口是否可见
      dialogAddCienmaRoomVisible: false,
      form: {
        movie_cinema_id: this.$route.params.id,
        room_name: "",
        room_type: "",
      },
      // 存储放映厅类型
      cinemaRootmTypes: [],
      // 存储所有放映厅
      tableData: [],
    }
  },
  methods: {
    // 弹出删除对话框
    showDelDialog(id) {
      this.$confirm("此操作将永久删除该影院, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$message({
          type: "success",
          message: "删除成功!",
        })
        this.$http.CinemaRoomApi.del({ id }).then((res) => {
          console.log(res)
          if (res.data.code == 200) {
            this.$message.success("删除成功")
            this.loadCinemaRoomsByCinemaId()
          }
        })
      })
    },
    // 显示添加放映厅对话框
    showAddCinemaRoomlog() {
      this.dialogAddCienmaRoomVisible = true
    },
    // 加载所有放映厅类型
    loadAllCinemaRootmTypes() {
      this.$http.CinemaRoomApi.queryAllTypes().then((res) => {
        // console.log("放映厅类型", res)
        this.cinemaRootmTypes = res.data.data
      })
    },
    // 提交添加放映厅
    onSubmit() {
      this.$http.CinemaRoomApi.add(this.form).then((res) => {
        console.log("提交添加放映厅请求", res)
        if (res.data.code == 200) {
          this.$message.success("添加成功")
          this.dialogAddCienmaRoomVisible = false
          this.form.room_name = ""
          this.form.room_type = ""
          this.loadCinemaRoomsByCinemaId()
        }
      })
    },
    // 通过id加载影院放映厅列表
    loadCinemaRoomsByCinemaId() {
      this.$http.CinemaRoomApi.list({
        cinema_id: this.form.movie_cinema_id,
      }).then((res) => {
        console.log("当前影院放映厅", res)
        if (res.data.code == 200) {
          this.tableData = res.data.data
        }
      })
    },
  },
  mounted() {
    //加载所有放映厅类型
    this.loadAllCinemaRootmTypes()
    // 加载当前影院的放映厅
    this.loadCinemaRoomsByCinemaId()
  },
}
</script>
